//切换支付类型
function ShowTab(id) {
    payChannelId =id;
}


function Show(id) {
    var id = id.toString();
    //var bankcode=id.substr(2);
    var str = id.split("_");
    var bankcode = "";
    var chiannelId = "";
    //加上数组长度判断，兼容像UPOP_ORG这种带下划线的bankCode
    if (str.length > 3) {
        for (var j = 1; j < str.length - 1; j++) {
            var tempStr = "";
            if (j == 1) {
                tempStr = str[j];
            } else {
                tempStr = "_" + str[j];
            }
            bankCode += tempStr;
        }
        chiannelId = str[str.length - 1];
    } else {
        bankCode = str[1];
        chiannelId = str[2];
    }
    ShowBankService(chiannelId);
    $("#" + id).attr("checked", true);
}

function ShowBankService(channelId) {
    var tag = "_service";
    $("table[id$='" + tag + "']").hide();
    $("#" + channelId + tag).show();
}

//加载函数
$(function () {
    initPage();
    var x = 41;
    var y = 20;
    $("a.tooltip").mouseover(function (e) {
        var merchantOrderId = $("#merchantOrderId").text();
        var txMoney = $("#txMoney").text();
        var subject = $("#subject").text();
        var remark = $("#remark").text();
        var body = $("#body").text();

        if (subject != null) {
            subject = subject.replace(/(^\s*)|(\s*$)/g, "");
        }

        if (remark != null) {
            remark = remark.replace(/(^\s*)|(\s*$)/g, "");
        }
        this.myTitle = this.title;
        this.title = "";
        var tooltip = "<div id='tooltip'><p><span class='tooltip-left' >订单号：<\/span><span class='right'>" + merchantOrderId + "<\/span><\/p><p><span class='tooltip-left'>订单金额：<\/span><span class='right'>" + txMoney + "<\/span><\/p>";
        if (!(subject == null || subject == "" || subject == "null")) {
            tooltip += "<p><span class='tooltip-left' style='text-align: right;width:80px; '>商品名称：<\/span><span class='right'>" + subject + "<\/span><\/p>";
        }
        if (!(remark == null || remark == "" || remark == "null")) {
            tooltip += "<p><span class='tooltip-left' style='text-align: right;'>商品描述：<\/span><span class='right'>" + remark + "<\/span><\/p>";
        }
        if (!(body == null || body == "" || body == "null")) {
            tooltip += "<p><span class='tooltip-left' style='text-align: right;'>商品主体：<\/span><span class='right'>" + body + "<\/span><\/p>";
        }
        tooltip += "<\/div>";
        $(".warp").append(tooltip);  //把它追加到文档中
        var tb_width = document.all.tooltip.offsetWidth;
        var head_width = getLeft(this);
        var tipadd = $("#tipadd").offset().left;
        var tleft = $("#tooltip").css('width');
        $("#tooltip").css({
            "top": 85 + "px",
            "right": "0px",
            "position": "absolute",
            "border": "1px solid #ccc",
            "display": "inline-block",
            "background": "rgb(255, 255, 255)",
            "line-height": "30px;"
        }).show("fast");
    }).mouseout(function () {
        this.title = this.myTitle;
        $("#tooltip").remove();   //移除
    });


});

//获取元素绝对x坐标
function getLeft(e) {
    var l = e.offsetLeft;
    while (e = e.offsetParent) {
        l += e.offsetLeft;
    }
    return l;
}

//提交表单
function submitForm(channelId) {
    ShowTab(channelId);
    var applyId = $("#applyId").val();
    if (applyId == null) {
        alert("支付单号不能为空！");
        return;
    }
    if (payChannelId == null) {
        alert("无效的支付方式！");
        return;
    }
    var url = "/Cashie/PayChannel/?applyId=" + applyId + "&channelId=" + payChannelId;
    openwin(url);
    var winHeight = 0;
    if (document.body && document.body.scrollHeight) {
        winHeight = document.body.scrollHeight;
    }
    $("#fade").css("height", winHeight + "px");
    $("#fade").show();
    $("#light").show();
}

function ProcessUrl(urltype, url) {

}

function openwin(url) {
    var a = document.createElement("a");
    a.setAttribute("href", url);
    a.setAttribute("target", "_blank");
    a.setAttribute("id", "openwin");
    document.body.appendChild(a);
    a.click();
}
function BuildPostForm(fm, url, target) {
    var e = null, el = [];
    if (!fm || !url)
        return e;
    target = target || '_blank';
    e = document.getElementById(fm);
    if (!e) {
        e = document.createElement('Form');
        e.Id = fm;
        document.body.appendChild(e);
    }
    e.method = 'post';
    e.target = target;
    e.style.display = 'none';
    e.enctype = 'application/x-www-form-urlencoded';

    var idx = url.indexOf('?');
    var para = [], op = [];
    if (idx > 0) {
        para = url.substring(idx + 1, url.length).split('&');
        url = url.substr(0, idx);//截取URL
        var keypair = [];
        for (var p = 0 ; p < para.length; p++) {
            idx = para[p].indexOf('=');
            if (idx > 0) {
                var txt = document.createElement("input");
                txt.name = para[p].substr(0, idx);
                txt.id = "frm" + para[p].substr(0, idx);
                txt.value = para[p].substring(idx + 1, para[p].length);
                e.appendChild(txt);
            }
            //if (idx > 0) {
            //    el.push('<input type="hidden" name="' + para[p].substr(0, idx) + '" id="frm' + para[p].substr(0, idx) + '" value="' + para[p].substring(idx + 1, para[p].length) + '" />');
            //}
        }
    }
    //e.innerHTML = el.join('');
    e.target = '_blank';
    e.action = url;
    return e;
};
//提交B2B表单
function b2bsubmitForm() {
    var bankCode = "";
    var chiannelId = "";
    var chkObjs = document.getElementsByName("payChannelId");
    for (var i = 0; i < chkObjs.length; i++) {
        if (chkObjs[i].checked) {
            var id = chkObjs[i].id.toString();
            var str = id.split("_");
            //加上数组长度判断，兼容像UPOP_ORG这种带下划线的bankCode
            if (str.length > 3) {
                for (var j = 1; j < str.length - 1; j++) {
                    var tempStr = "";
                    if (j == 1) {
                        tempStr = str[j];
                    } else {
                        tempStr = "_" + str[j];
                    }
                    bankCode += tempStr;
                }
                chiannelId = str[str.length - 1];
            } else {
                bankCode = str[1];
                chiannelId = str[2];
            }
            break;
        }
    }
    //非银行卡支付不更新Cookie
    if (bankCode != "CMPAY" && bankCode != "ZYC") {
        //保存24小时
        setCookie("b2btempChannelId", chiannelId, 24);
    }
    var redoFlag = $("#redoFlag").val();
    if ("1" == redoFlag) {
        $("#" + formname).attr("target", "_self");
    } else {
        openDialog();
        $("#" + formname).attr("target", "dinpay");
    }
    $("#" + formname).submit();
}

//提交表单
function submitForm_scanPay(formname) {
    var scan2d = $("#scan2d").val();
    var txMoney = $("#amount").val();
    if (txMoney > 50000) {
        $("#fade").show();
        $("#scan_pay_over").show();
        return;
    }


    if (scan2d.trim() != '') {
        $("#fade").show();
        $("#scan_window").show();
        return;
    }
    var url = $("#bank_scanpay").attr("action");
    var dataStr = "";
    var bankCode = "";
    var chiannelId = "";
    var orderKey = $("#orderKey").val();
    var orderInfo = $("#orderInfo").val();
    var chkObjs = $('#' + formname + " input[name='payChannelId']");
    var chlType = $("#chlType").val();
    var checkedId = "";
    for (var i = 0; i < chkObjs.length; i++) {
        if (chkObjs[i].checked) {
            var id = chkObjs[i].id.toString();
            checkedId = id;
            var str = id.split("_");
            bankCode = str[1];
            chiannelId = str[2];
            break;
        } else {
            if (i == chkObjs.length - 1) {
                alert("请选择支付银行");
                return false;
            }

        }
    }


    payChannelId = $("#" + checkedId).val();
    dataStr += "bankCode=" + bankCode + "&payChannelId=" + payChannelId + "&orderKey=" + orderKey + "&orderInfo=" + orderInfo + "&chlType=" + chlType;
    $.ajax({
        type: "post",
        url: url,
        dataType: "responseText",
        data: dataStr,
        success: function (result) {
            var data = eval("(" + result + ")");
            if (data.qrcode != "") {
                openDialog_scanPay("scan_window");
                var oQRCode = new QRCode("qrcode", {
                    width: 200,
                    height: 200
                });
                oQRCode.clear();
                $("#dinpayLogo").css("display", "block");
                oQRCode.makeCode(data.qrcode);
                $("#scan2d").val(data.qrcode);
            } else {
                openDialog_scanPay("scan_window_excption");
                var code = data.errorcode;
                var desc = data.errordesc;
                $("#scan_window_excption").find("#msg").html(code);
                $("#scan_window_excption").find("#showMsg").html(desc);
            }
        }
    });
    $("#" + formname).attr("target", "dinpay");
}

//打开遮罩层
var intime;
function openDialog() {
    //触发检查订单状态
    setTimeout(function () { intime = setInterval("checkSuccess('PaymentCom')", 60000); }, 300000);
    //websocket连接推送网关
    openWebsocket();
    var winHeight = 0;
    if (document.body && document.body.scrollHeight) {
        winHeight = document.body.scrollHeight;
    }
    $("#fade").css("height", winHeight + "px");
    $("#fade").show();
    $("#light").show();
}

function openDialog_scanPay(scan_window) {
    //触发检查订单状态
    setTimeout(function () { intime = setInterval("checkSuccess('PaymentCom')", 60000); }, 300000);
    //websocket连接推送网关
    openWebsocket();
    var winHeight = 0;
    if (document.body && document.body.scrollHeight) {
        winHeight = document.body.scrollHeight;
    }
    $("#fade").show();
    $("#" + scan_window).show();
}

//关闭遮罩层
function closeDialog() {
    $("#fade").hide();
    $("#light").hide();
}
//设置Cookie
function setCookie(name, value, expireHours) {
    var cookieString = name + "=" + escape(value);
    if (expireHours > 0) {
        var exp = new Date();
        exp.setTime(exp.getTime() + expireHours * 60 * 60 * 1000);
        cookieString = cookieString + "; expires=" + exp.toGMTString();
    }
    document.cookie = cookieString;
}
//获取Cookie
function getCookie(name) {
    var strCookie = document.cookie;
    var arrCookie = strCookie.split("; ");
    for (var i = 0; i < arrCookie.length; i++) {
        var arr = arrCookie[i].split("=");
        if (arr[0] == name) {
            return arr[1]
        };
    }
    return "0";
}

function getObjectId(obj) {
    var id = null;//这个是要的id       
    if (obj) {
        id = obj.id;
    }
    return id;
}

//初始化
function initPage() {

    // var allbank = [ "ICBC", "BCOM", "SDB", "ECITIC", "ABC", "CMB", "CMBC", "CEBB","NBB","BOB",
    //                        "CCB", "SPABANK", "BEA", "BOC", "PSBC", "CIB", "GDB", "HXB", "SPDB", "CMBC2", "ECITIC2","BHB", "HSBANK"];
    var tmpStr = getCookie("tempChannelId");
    var b2btmpStr = getCookie("b2btempChannelId");
    var dcardTmpStr = getCookie("dcardTmpBankId");
    //Cookie是否存在
    //if(tmpStr=="0"){
    //   tmpStr="ICBC";
    //  }
    // if(b2btmpStr=="0"){
    //  b2btmpStr="ICBC";
    // }
    //银行是否正确
    //var tmpFlag=$.inArray(tmpStr, allbank);
    // if(tmpFlag==-1){
    //    tmpStr="ICBC";
    // }
    // var b2btmpFlag=$.inArray(b2btmpStr, allbank);
    // if(b2btmpFlag==-1){
    //    b2btmpStr="ICBC";
    // }
    //   ShowBankService(tmpStr);
    his_bank = "his_" + tmpStr;

    b2b_his_bank = "b2b_his_" + b2btmpStr;
    dcard_his_bank = "dcad_his" + dcardTmpStr;

    payChannelId = "AliPay.Transfer";

    //   	$("#"+his_bank).show();
    //     $("#"+his_bank).attr("checked",true);
    //   $("#"+b2b_his_bank).show();
    //   $("#"+b2b_his_bank+" "+"input:first").attr("checked",true);
    $("#" + dcard_his_bank).parent().show();
    $("#" + dcard_his_bank).attr("checked", true);


    var tempId = $("#ul_button").find("li:eq(0)").attr("id");
    if (tempId == "tab4") {
        ShowBankService(b2btmpStr);
    }
    ShowTab(tempId, 4);
}

function showPro(url) {
    var wid = $(window).width();
    var hei = $(window).height();
    var lef = (wid - 600) / 2 + "px";
    var heii = (hei - 400) / 2 + "px";
    $(".terms").css({
        "left": lef,
        "top": heii
    })
    $(".bg").css({
        "opacity": 0.7,
        "width": wid,
        "height": hei + 200
    });
    $(".bg").css("display", "block");
    document.getElementById('proess').style.display = "";
    $("#fade").hide();
    $("#light").hide();
    var dataStr = "orderKey=" + $("#orderKey").val();
    var isCheckBank = "isCheckBank=0";
    $.ajax({
        type: "post",
        url: url,
        dataType: "responseText",
        data: dataStr + "&" + isCheckBank + "&timeStamp=" + (new Date().getTime()),
        success: function (result) {
            var data = eval("(" + result + ")");
            if (data.result == "0") {
                postForm(data);
            } else {
                $(".bg").css("display", "none");
                document.getElementById('proess').style.display = "none";
                $("#fade").show();
                $("#light_fail").show();
            }
        }
    });
}

function showPro_scanPay(url, form) {
    var wid = $(window).width();
    var hei = $(window).height();
    var lef = (wid - 600) / 2 + "px";
    var heii = (hei - 400) / 2 + "px";
    $(".terms").css({
        "left": lef,
        "top": heii
    })
    $(".bg").css({
        "opacity": 0.7,
        "width": wid,
        "height": hei + 200
    });
    $(".bg").css("display", "block");
    document.getElementById('proess').style.display = "";
    $("#fade").hide();
    $("#" + form).hide();
    var dataStr = "orderKey=" + $("#orderKey").val();
    var isCheckBank = "isCheckBank=0";
    $.ajax({
        type: "post",
        url: url,
        dataType: "responseText",
        data: dataStr + "&" + isCheckBank + "&timeStamp=" + (new Date().getTime()),
        success: function (result) {
            var data = eval("(" + result + ")");
            if (data.result == "0") {
                postForm(data);
            } else {
                $(".bg").css("display", "none");
                document.getElementById('proess').style.display = "none";
                $("#fade").show();
                $("#light_fail").show();
            }
        }
    });
}

function closeDialog1() {
    $("#fade").hide();
    $("#light_fail").hide();
}

function closeDialog_scanPay(form) {
    $("#fade").hide();
    $("#" + form).hide();
}

function openWebsocket() {
    var url = $("#pushUrl").val();
    var policyUrl = $("#policyUrl").val();
    if (!url) {
        return;
    }
    var ws;
    if (policyUrl) {
        try {
            WebSocket.loadFlashPolicyFile(policyUrl);
        } catch (e) {
        }
    }
    try {
        ws = new WebSocket(url);
    } catch (e) {
        console.log(e);
        return;
    }
    ws.onopen = function () {
        console.log('connect pushGateway success.')
    }
    ws.onmessage = function (e) {
        var data = eval("(" + e.data + ")");
        if (data.result == "0") {
            checkSuccess('PaymentCom');
        }
    }
    ws.onclose = function (e) {
        if (e.code == 1000) {//正常关闭（超时、业务已完成）
            //do nothing
            console.log('connect close', e.code + ":" + e.reason)
        } else if (e.code == 1003) {//服务器拒绝连接
            //do nothing
            console.log('connect close', e.code + ":" + e.reason)
        } else {//重新连接
            setTimeout("openWebsocket()", 10000);
        }
    }
}

function checkSuccess(url) {
    var dataStr = "orderKey=" + $("#orderKey").val();
    var isCheckBank = "isCheckBank=1";
    $.ajax({
        type: "post",
        url: url,
        dataType: "responseText",
        data: dataStr + "&" + isCheckBank + "&timeStamp=" + (new Date().getTime()),
        success: function (result) {
            var data = eval("(" + result + ")");
            if (data.result == "0") {
                postForm(data);
            } if (data.result == "2") {
                var turnForm = document.createElement("form");
                document.body.appendChild(turnForm);
                turnForm.method = 'post';
                turnForm.action = 'cekWrong.jsp';
                //创建隐藏表单
                var newElement = document.createElement("input");
                newElement.setAttribute("name", "errorCode");
                newElement.setAttribute("type", "hidden");
                newElement.setAttribute("value", data.errorCode);
                turnForm.appendChild(newElement);
                turnForm.submit();
            }
        }
    });
}

function checkPay(url) {
    closeDialog();
    //var wid = $(window).width();
    //var hei = $(window).height();
    //var lef = (wid - 600) / 2 + "px";
    //var heii = (hei - 400) / 2 + "px";
    //$(".terms").css({
    //    "left": lef,
    //    "top": heii
    //})
    //$(".bg").css({
    //    "opacity": 0.7,
    //    "width": wid,
    //    "height": hei + 200
    //});
    //$(".bg").css("display", "block");
    //document.getElementById('proess').style.display = "";
    //clearInterval(intime);
    //$("#fade").hide();
    //$("#light").hide();
    //$("#scan_pay_over").hide();
    //var dataStr = "orderKey=" + $("#orderKey").val();
    //var isCheckBank = "isCheckBank=0";
    //$.ajax({
    //    type: "post",
    //    url: url,
    //    dataType: "responseText",
    //    data: dataStr + "&" + isCheckBank + "&timeStamp=" + (new Date().getTime()),
    //    success: function (result) {
    //        var data = eval("(" + result + ")");
    //        if (data.result == "0") {
    //            postForm(data);
    //        } else {
    //            $(".bg").css("display", "none");
    //            document.getElementById('proess').style.display = "none";
    //        }
    //    }
    //});
}

function checkPay_scanPay(url) {
    var wid = $(window).width();
    var hei = $(window).height();
    var lef = (wid - 600) / 2 + "px";
    var heii = (hei - 400) / 2 + "px";
    $(".terms").css({
        "left": lef,
        "top": heii
    })
    $(".bg").css({
        "opacity": 0.7,
        "width": wid,
        "height": hei + 200
    });
    $(".bg").css("display", "block");
    document.getElementById('proess').style.display = "";
    clearInterval(intime);
    $("#fade").hide();
    $("#scan_window").hide();
    var dataStr = "orderKey=" + $("#orderKey").val();
    var isCheckBank = "isCheckBank=0";
    $.ajax({
        type: "post",
        url: url,
        dataType: "responseText",
        data: dataStr + "&" + isCheckBank + "&timeStamp=" + (new Date().getTime()),
        success: function (result) {
            var data = eval("(" + result + ")");
            if (data.result == "0") {
                postForm(data);
            } else {
                $(".bg").css("display", "none");
                document.getElementById('proess').style.display = "none";
            }
        }
    });
}

function submitToErrorPage(errorCode) {
    var form = $("<form></form>");
    form.attr("action", "checkWrong.jsp");
    form.action = "checkWrong.jsp";
    var input = $("<input />");
    input.attr("name", "errorCode");
    input.attr("value", errorCode);
    input.attr("type", "hidden");
    form.append(input);
    $("body").append(form);
    //	alert(form);
    form.submit();
}

if (!util) {
    var util = {};
}
if (!util.page) {
    util.page = function () {
    };
    util.page.prototype.disableContextMenu = function () {
        $(document).bind('contextmenu', function () {
            return false;
        });
    };
    util.page.prototype.init = function () {
        this.disableContextMenu();
    };
}
$(document).ready(function () {
    var page = new util.page();
    page.init();
});

function postForm(data) {
    var turnForm = document.createElement("form");
    document.body.appendChild(turnForm);
    turnForm.method = 'post';
    turnForm.action = 'check_succeed.jsp';
    //创建隐藏表单
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "orderId");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.orderId);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "txMoney");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.txMoney);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "txDate");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.txDate);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "gateWayID");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.gateWayID);
    turnForm.appendChild(newElement);
    //新增
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "order_version");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.order_version);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "newmd5info");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.newmd5info);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "DinpayOrderId");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.DinpayOrderId);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "m_id");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.m_id);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "m_orderid");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.m_orderid);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "m_oamount");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.m_oamount);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "m_ocurrency");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.m_ocurrency);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "m_language");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.m_language);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "s_name");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.s_name);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "s_addr");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.s_addr);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "s_postcode");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.s_postcode);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "s_tel");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.s_tel);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "s_eml");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.s_eml);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "r_name");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.r_name);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "r_addr");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.r_addr);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "r_postcode");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.r_postcode);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "r_eml");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.r_eml);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "r_tel");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.r_tel);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "m_ocomment");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.m_ocomment);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "m_status");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.m_status);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "modate");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.modate);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "OrderMessage");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.OrderMessage);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "Digest");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.Digest);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "merchant_code");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.merchant_code);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "notify_type");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.notify_type);
    turnForm.appendChild(newElement);

    var newElement = document.createElement("input");
    newElement.setAttribute("name", "notify_id");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.notify_id);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "interface_version");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.interface_version);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "sign_type");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.sign_type);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "order_no");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.order_no);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "order_amount");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.order_amount);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "order_time");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.order_time);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "trade_no");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.trade_no);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "trade_time");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.trade_time);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "trade_status");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.trade_status);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "extra_return_param");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.extra_return_param);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "bank_seq_no");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.bank_seq_no);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "page_sign");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.page_sign);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "page_return_url");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.page_return_url);
    turnForm.appendChild(newElement);
    var newElement = document.createElement("input");
    newElement.setAttribute("name", "s_postcode");
    newElement.setAttribute("type", "hidden");
    newElement.setAttribute("value", data.s_postcode);
    turnForm.appendChild(newElement);
    turnForm.submit();
}
